package org.dev.app.controller;


import org.dev.app.entity.Dept;
import org.dev.app.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author Wangzz
 * @since 2022-05-25
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
	@Autowired
	private DeptService deptService;


	@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
	public Dept get(@PathVariable("id") int id) {
		return deptService.getById(id);
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public List<Dept> list() {
		return deptService.list();
	}

	// 超时测试，该服务的响应时间为5秒
	@RequestMapping(value = "/feign/timeout")
	public String deptFeignTimeout() {
		// mock stop 5s
		try {
			TimeUnit.SECONDS.sleep(5);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "超时测试!";
	}
}

